package com.example.myapplication;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class Myadapter2 extends RecyclerView.Adapter<Myadapter2.Myholder>{
    Context context2;
    List<Map<String,Object>> list2;
    public Myadapter2(Context context, List<Map<String,Object>> list){
        this.context2 = context;
        this.list2 = list;
    }


    @NonNull
    @Override
    public Myholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context2).inflate(R.layout.item2,parent,false);
        Myholder holder=new Myholder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull Myholder holder, int position) {
        Map<String,Object> itemMap = list2.get(position);
        int picture= Objects.requireNonNull(itemMap.get("picture")).hashCode();
        String text1= Objects.requireNonNull(itemMap.get("name").toString());
        holder.textView.setText(text1);
        holder.imageView.setImageResource(picture);
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context2, Activity_Detail.class);
                intent.putExtra("name",text1);
                intent.putExtra("picture",picture);
                context2.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {

        return list2.size();
    }




    public class Myholder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;
        public Myholder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.item_textView2);
            imageView = itemView.findViewById(R.id.item_imageView2);
        }
    }

}
